#include<bits/stdc++.h>
int  q[100005][6]={0};
using namespace std;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int a,s,d,f,g,h,k=0,l=0;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
        l=0;
        cin>>s>>d>>f>>g;
        for(int j=1;j<=s;j++)
        {
            cin>>q[j][1]>>q[j][2]>>q[j][3];
        }
        for(int j=1;j<=d;j++)
        {
            cin>>k;
        }
        for(int j=1;j<=s;j++)
        {
            if(q[j][3]==0)
            {
                if(q[j][2]>g&&q[j][1]<=k)
                {
                    l++;
                }
            }
            if(q[j][3]>0)
            {
                if(q[j][2]>g&&q[j][1]<=k)
                {
                    l++;
                }
                else
                {
                    if(double(sqrt(q[j][2]*q[j][2]+2*q[j][3]*(k-q[j][1])))>g&&q[j][1]<=k)
                        l++;
                }

            }
        }
        if(l==0)  ++d;
        cout<<l<<" "<<d-1<<endl;
    }
    return 0;
}
